草庐IT

c++ - Clang、std::next、libstdc++ 和 constexpr-ness

全部标签

c++ - 需要帮助在 Windows 上正确设置 CLANG

我需要一些帮助才能在Windows上正确设置clang。我安装了VisualStudios2015。和WindowsSDK。我最近安装了Clang,并通过它运行了一个非常基本的helloworld以确保它正常工作。它给了我一个我无法理解的错误。VisualStudios会处理得很好。这是我从clang收到的错误输出:MicrosoftWindows[Version10.0.14393]C:\Users\Leo>cdC:\Users\Leo\Desktop\SandboxC:\Users\Leo\Desktop\Sandbox>clang++hello.cppInfileincluded

c++ - 调用时为 std::function 分配新值

inti=9;struct_variable.f=[i](Tstruct_variable&){do_something_with_capture_variable(i);...struct_variable.f=another_compatible_std_function;//dosomethingelse,butneverusecapturedvariableafterhere...};struct_variable.f(struct_variable);lambda函数被保存为成员struct_variable.f(也是类型std::function),在回调中,struct_

c++ - 如何允许 clang-format 在一行中格式化空类/结构?

具有以下结构定义:structcity{};structcountry{};我想要clang-format像这样为我格式化structcity{};structcountry{};我怎样才能做到这一点?我可以看到很多选项,例如AllowShortBlocksOnASingleLine、AllowShortFunctionsOnASingleLine或AllowShortIfStatementsOnASingleLine但没有AllowShortClassDefinitionsOnASingleLine(或类似的). 最佳答案 很遗憾

gcc - 为什么要在项目中使用#include_next?

引用iOSDocumentationonWrapperHeaders:#include_nextdoesnotdistinguishbetweenand"file"inclusion,nordoesitcheckthatthefileyouspecifyhasthesamenameasthecurrentfile.Itsimplylooksforthefilenamed,startingwiththedirectoryinthesearchpathaftertheonewherethecurrentfilewasfound.Theuseof`#include_next'canleadt

c++ - 为什么 std::shared_ptr 提供 operator<<?

std::shared_ptr提供operator它只是写出它的地址。没有operator>>只记录地址,不记录内容。我想知道它在哪些情况下有用。 最佳答案 因为是一个潜在有用的东西在原始指针上执行。这是安全的,原始指针就是这样做的,shared_ptr在某些情况下应该用于替换原始指针。相比之下,>>很少有意义。与原始指针不同,将指针值存储在共享指针中会取得它的所有权。我可以some_stream>>raw_ptr除非我用ptr做些什么没有任何问题;有点奇怪,但没有立即中断。对shared_ptr做同样的事情只有在极其深奥的情况下才

c++ - 不完整类型的 std::unique_ptr 无法编译

我将pimpl-idiom与std::unique_ptr结合使用:classwindow{window(constrectangle&rect);private:classwindow_impl;//definedelsewherestd::unique_ptrimpl_;//won'tcompile};但是,我在的第304行收到关于使用不完整类型的编译错误:Invalidapplicationof'sizeof'toanincompletetype'uixx::window::window_impl'据我所知,std::unique_ptr应该能够与不完整的类型一起使用。这是lib

c++ - libstdc++新标准库特性支持表

是否有表格指定新标准(11和14)对以前版本的GNUlibstdc++的支持?我为compiler找到了这样的表格和currentlibstate.但是我如何确定gcc4.6版是否支持std::queue::emplace和std::result_of_t。 最佳答案 旧版本库的手册都链接自https://gcc.gnu.org/onlinedocs每个版本的更改都列在发行说明中,例如https://gcc.gnu.org/gcc-4.6/changes.html在最新版本C++17statusdocs,我们现在还列出了引入该功能的

c++ - 用于 cv::Mat 参数的 OpenCV std::vector

执行这个:std::vectorpts;//contains4elementscv::MatptsMat=((cv::InputArray)pts).getMat();在一台机器上,我得到一个带有2个channel的4-by-1cv::Mat。每个元素代表一个二维点。在另一台机器上,我得到一个2090-by-1cv::Mat,它有2个channel,数据很奇怪。这是错误的,这是一个问题,因为vector只包含4个项目。在两台机器上都使用OpenCV3.1从源代码构建,在Windows10上使用CMake。编辑我开始在另一台机器上遇到类似的问题。在Debug模式下的VisualStudi

c++ - 为什么可以将 std::bind 分配给参数不匹配的 std::function?

我有如下代码:#include#includeusingnamespacestd;voidF(intx){coutf1=std::bind(F,std::placeholders::_1);f1(100);//Thisworks,willprint100.intx=0;std::functionf2=std::bind(F,x);f2();//Thisworks,willprint0.std::functionf3=std::bind(F,x);f3(200);//BUTWHYTHISWORKS??????Itprints0.return0;}我的编译器信息是:AppleLLVM版本6

c++ - 使用 std::hexfloat 读写

这段代码在我的机器上打印了0,但我期望是0.3。怎么了?我在最新的ArchLinux上使用g++6.3.1。编译标志似乎无关紧要。#include#includeintmain(){std::stringstreams;s>std::hexfloat>>d)std::cout 最佳答案 使用doubled=std::strtod(s.str().c_str(),NULL);作为解决方法。这似乎是一个错误。 关于c++-使用std::hexfloat读写,我们在StackOverflow上